/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.prolificinteractive.materialcalendarview.sample;

import ohos.aafwk.content.Intent;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.CalendarMode;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
import com.prolificinteractive.materialcalendarview.sample.decorators.HighlightWeekendsDecorator;
import com.prolificinteractive.materialcalendarview.sample.decorators.MySelectorDecorator;

import org.threeten.bp.LocalDate;
import org.threeten.bp.Month;

/**
 * @since 2021-07-12
 */
public class SwappableBasicAbilityDecorated extends BaseAbility implements OnDateSelectedListener {
    private MaterialCalendarView widget;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        toolbarTitle.setText("Calendar with Dynamic Modes");
        widget = (MaterialCalendarView) findComponentById(ResourceTable.Id_calendarView);
        widget.setOnDateChangedListener(this);
        widget.setShowOtherDates(7);
        final LocalDate instance = LocalDate.now();

        final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
        final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);
        widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();
        widget.isBigSize(true);
        widget.addDecorators(
            new MySelectorDecorator(this),
            new HighlightWeekendsDecorator()
        );
        findComponentById(ResourceTable.Id_button_weeks).setClickedListener(component ->
            widget.state().edit()
                .setCalendarDisplayMode(CalendarMode.WEEKS)
                .commit());
        findComponentById(ResourceTable.Id_button_months).setClickedListener(component ->
            widget.state().edit()
                .setCalendarDisplayMode(CalendarMode.MONTHS)
                .commit());
        widget.setSelectedDate(instance);
    }

    @Override
    int contentLayoutRes() {
        return ResourceTable.Layout_ability_basic_modes;
    }

    @Override
    public void onDateSelected(MaterialCalendarView widget, CalendarDay date, boolean selected) {

    }
}
